import loginModule from "./login";

import Vue from "vue";
import Vuex from "vuex";
import { getInfoConfig } from "@/service/content";
Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    Zhengche: [],
    Tongzhi: [],
    News: [],
    contentInfoConfig: {
      archival_information: {},
    },
  },
  mutations: {
    setZhengcheData(state, payload) {
      state.Zhengche.push(payload);
      // console.log(state.Zhengche);
    },

    setTongzhiData(state, tongzhiData) {
      state.Tongzhi.push(tongzhiData);
      // console.log(state.Tongzhi);
    },

    setNewsData(state, NewsData) {
      state.News.push(NewsData);
      // console.log(state.News);
    },
    setContentInfoConfig(state, payload) {
      payload[0].link = JSON.parse(payload[0].link);
      payload[0].archival_information = JSON.parse(
        payload[0].archival_information
      );
      state.contentInfoConfig = payload[0];
    },
  },
  actions: {
    async getInfoConfig({ commit }) {
      const { data: res } = await getInfoConfig();
      commit("setContentInfoConfig", res);
    },
  },
  modules: { loginModule },
});
